﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.SellStocks;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace MangoMes.Write.API.Applications.SellStockSearchWrite
{
    public class ProductsSaleCreateHandler : IRequestHandler<ProductsSaleCreateCommand, ResultsDTO>
    {
        private readonly IBateRepository<ProductsSale> _productssaleRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="productssaleRepository"></param>
        public ProductsSaleCreateHandler(IBateRepository<ProductsSale> productssaleRepository)
        {
            _productssaleRepository = productssaleRepository;
        }
        /// <summary>
        /// 产品销售新增
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ResultsDTO> Handle(ProductsSaleCreateCommand request, CancellationToken cancellationToken)
        {
            DapperHelper dapperHelper = new DapperHelper();
            ResultsDTO res = new ResultsDTO { Code = 0 };
            ProductsSale per = new ProductsSale();
            per.ProductsSaleId = request.ProductsSaleId;
            per.ProductsSaleNo = request.ProductsSaleNo;
            per.StashId = request.StashId;
            per.ProductionWorkOrdersNo = request.ProductionWorkOrdersNo;
            per.ProductsSaleYesNo = request.ProductsSaleYesNo;
            per.ProductsSaleDemand = request.ProductsSaleDemand;
            per.SellStockNo = request.SellStockNo;
            per.ProductManageNode = request.ProductManageNode;
            per.ProductsSaleNum = request.ProductsSaleNum;
            per.ProductsSaleBuer = request.ProductsSaleBuer;
            string conn = dapperHelper.MangoMesWrite;
            string str = "insert into productssale values(@ProductsSaleId,@ProductsSaleNo,@StashId,@ProductionWorkOrdersNo" +
                ",@ProductsSaleYesNo,@ProductsSaleDemand,@SellStockNo,@ProductManageNode,@ProductsSaleNum,@ProductsSaleBuer)";
            res.Code = await _productssaleRepository.Add(str, per, conn);
            return res;
        }
    }
}
